// pages/coupondetails/details.js
const api = require("../../../utils/interface.js")
const math = require("../../../utils/math.js")
const tools = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    timeOut: "",//到期时间
    productName: "",//油品类型
    storeName: "",//可用油站
    preAmount: "",//优惠金额
    couponName: "",//优惠券名称
    couponList:null,
    storeLists:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options, "55")
    let memberCouponId = options.memberCouponId
    this.getOrderList(memberCouponId)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  getOrderList(item) {
    let that = this
    api.getCouponById({ couponId: item }).then(res => {
      console.log(res, "yang")
      let couponList = res.data.result
      let storeLists = res.data.result.storeNames.split(",")
      let timeOut = tools.formatTime(new Date(res.data.result.endDate))
      let preAmount = math.divide(res.data.result.preAmount, 100)
      let couponName = res.data.result.couponName
      that.setData({
        couponList: couponList,
        preAmount:preAmount,
        storeLists:storeLists,
        timeOut:timeOut
      })
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})